const {pushClaims,getClaims,modifyClaims,applyClaims,deleteClaims} =require('../dao/modules/claimsDao')
const {moveFiles, deleteFiles } =require('../util/handleFiles')
//销售员新增理赔订单
module.exports.pushClaims = async(proms) => {
   const data=await pushClaims(proms)
   if (data._id) {
      // 移动图片
      moveFiles({
          fromPath: './public/temp',
          toPath: './public/images/claimsImgs',
          filename: proms.voucher
      });
      // 删除临时文件夹
      deleteFiles('./public/temp');
      return {
          message: '添加成功',
          status: 1
      }
  } else {
      return {
          message: '添加失败',
          status: 0
      }
  }
   return data
}
//销售员获取所有理赔订单
module.exports.getClaims = async(proms) => {
    const data=await getClaims(proms)
    return data
 }

//销售员修改理赔信息并提交
module.exports.modifyClaims = async(proms) => {
    const data=await modifyClaims(proms)
    if(data.nModified==1){
        return{
            data,
            message:'修改成功',
            status:1
        }
    }else{
        return{
            message:'修改失败',
            status:1
        }
    }
 }

 //管理员处理理赔订单
module.exports.applyClaims = async(proms) => {
    const data=await applyClaims(proms)
    if(data.nModified>0){
        return{
            data,
            message:'处理理赔成功',
            status:1
        }
    }else{
        return{
            message:'处理理赔失败',
            status:1
        }
    }
   
 }

 //管理员删除理赔订单
module.exports.deleteClaims = async(proms) => {
    const data=await deleteClaims(proms)
    if(data.nModified>0){
        return{
            data,
            message:'删除成功',
            status:1
        }
    }else{
        return{
            message:'删除失败',
            status:1
        }
    }
 }